//
//  RNIOSExportJsToReact.m
//  xmgjAppFront
//
//  Created by 汪滔 on 2020/7/1.
//

#import <Foundation/Foundation.h>
#import "AddressChooseModule.h"
#import <React/RCTLog.h>

#import "ZHFAddTitleAddressView.h"

@interface AddressChooseModule ()
@property (nonatomic, strong)ZHFAddTitleAddressView *addTitleAddressView;
@end

@implementation AddressChooseModule
RCTResponseSenderBlock AddressSender;
RCT_EXPORT_MODULE();


RCT_EXPORT_METHOD(openWindow:(NSDictionary *)params  callback:(RCTResponseSenderBlock) callback){
  AddressSender = callback;
  NSInteger level = params[@"level"] ? [params[@"level"] integerValue]: 4;
  //弹出地址选择器
  dispatch_async(dispatch_get_main_queue(), ^{
    [self chooseAddressWithLevel:level];
   });
}
-(id)init{
  if (self=[super init]) {
    
  }
  return self;
}

-(void)chooseAddressWithLevel:(NSInteger )level
{
  self.addTitleAddressView = [[ZHFAddTitleAddressView alloc]init];
  self.addTitleAddressView.title = @"选择地址";
  self.addTitleAddressView.defaultHeight = 350;
  self.addTitleAddressView.titleScrollViewH = 37;
  self.addTitleAddressView.numberOfLevel = level;
  if (self.addTitleAddressView.titleIDMarr.count > 0) {
    self.addTitleAddressView.isChangeAddress = true;
  }
  else{
    self.addTitleAddressView.isChangeAddress = false;
  }
  @weakify(self);
  self.addTitleAddressView.callBackBlcok = ^(NSDictionary *addressDic) {
    @strongify(self);
    if (AddressSender != nil) {
      AddressSender(@[[addressDic jsonStringEncoded]]);
    }
    [self.addTitleAddressView removeFromSuperview];
  };
  
  [[UIApplication sharedApplication].keyWindow addSubview:[self.addTitleAddressView initAddressView]];
  [self.addTitleAddressView addAnimate];
}

@end
